package runesim.node.net.codec;

import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;

/**
 * Provides access to the protocol encoders and decoders for the RSC protocol.
 */
public class RS2CodecFactory implements ProtocolCodecFactory {
	
	/**
	 * The protocol encoder in use
	 */
	private static ProtocolEncoder encoder;
	/**
	 * The protocol decoder in use
	 */
	private static ProtocolDecoder decoder;
	
	/**
	 * Provides the encoder to use to parse incoming data.
	 * 
	 * @return A protocol encoder
	 */
	public ProtocolEncoder getEncoder() {
		return encoder;
	}
	
	/**
	 * Provides the decoder to use to format outgoing data.
	 * 
	 * @return A protocol decoder
	 */
	public ProtocolDecoder getDecoder() {
		return decoder;
	}
	
	static {
		final int[] packetLengthsIn = new int[256];
		packetLengthsIn[0] = 0;
		packetLengthsIn[1] = 0;
		packetLengthsIn[2] = 0;
		packetLengthsIn[3] = 1;
		packetLengthsIn[4] = -1;
		packetLengthsIn[5] = 0;
		packetLengthsIn[6] = 0;
		packetLengthsIn[7] = 0;
		packetLengthsIn[8] = 0;
		packetLengthsIn[9] = 0;
		packetLengthsIn[10] = 0;
		packetLengthsIn[11] = 0;
		packetLengthsIn[12] = 0;
		packetLengthsIn[13] = 0;
		packetLengthsIn[14] = 8;
		packetLengthsIn[15] = 0;
		packetLengthsIn[16] = 6;
		packetLengthsIn[17] = 2;
		packetLengthsIn[18] = 2;
		packetLengthsIn[19] = 0;
		packetLengthsIn[20] = 0;
		packetLengthsIn[21] = 2;
		packetLengthsIn[22] = 0;
		packetLengthsIn[23] = 6;
		packetLengthsIn[24] = 0;
		packetLengthsIn[25] = 12;
		packetLengthsIn[26] = 0;
		packetLengthsIn[27] = 0;
		packetLengthsIn[28] = 0;
		packetLengthsIn[29] = 0;
		packetLengthsIn[30] = 0;
		packetLengthsIn[31] = 0;
		packetLengthsIn[32] = 0;
		packetLengthsIn[33] = 0;
		packetLengthsIn[34] = 0;
		packetLengthsIn[35] = 8;
		packetLengthsIn[36] = 4;
		packetLengthsIn[37] = 0;
		packetLengthsIn[38] = 0;
		packetLengthsIn[39] = 2;
		packetLengthsIn[40] = 2;
		packetLengthsIn[41] = 6;
		packetLengthsIn[42] = 0;
		packetLengthsIn[43] = 6;
		packetLengthsIn[44] = 0;
		packetLengthsIn[45] = -1;
		packetLengthsIn[46] = 0;
		packetLengthsIn[47] = 0;
		packetLengthsIn[48] = 0;
		packetLengthsIn[49] = 0;
		packetLengthsIn[50] = 0;
		packetLengthsIn[51] = 0;
		packetLengthsIn[52] = 0;
		packetLengthsIn[53] = 12;
		packetLengthsIn[54] = 0;
		packetLengthsIn[55] = 0;
		packetLengthsIn[56] = 0;
		packetLengthsIn[57] = 0;
		packetLengthsIn[58] = 8;
		packetLengthsIn[59] = 0;
		packetLengthsIn[60] = 0;
		packetLengthsIn[61] = 8;
		packetLengthsIn[62] = 0;
		packetLengthsIn[63] = 0;
		packetLengthsIn[64] = 0;
		packetLengthsIn[65] = 0;
		packetLengthsIn[66] = 0;
		packetLengthsIn[67] = 0;
		packetLengthsIn[68] = 0;
		packetLengthsIn[69] = 0;
		packetLengthsIn[70] = 6;
		packetLengthsIn[71] = 0;
		packetLengthsIn[72] = 2;
		packetLengthsIn[73] = 2;
		packetLengthsIn[74] = 8;
		packetLengthsIn[75] = 6;
		packetLengthsIn[76] = 0;
		packetLengthsIn[77] = -1;
		packetLengthsIn[78] = 0;
		packetLengthsIn[79] = 6;
		packetLengthsIn[80] = 0;
		packetLengthsIn[81] = 0;
		packetLengthsIn[82] = 0;
		packetLengthsIn[83] = 0;
		packetLengthsIn[84] = 0;
		packetLengthsIn[85] = 1;
		packetLengthsIn[86] = 4;
		packetLengthsIn[87] = 6;
		packetLengthsIn[88] = 0;
		packetLengthsIn[89] = 0;
		packetLengthsIn[90] = 0;
		packetLengthsIn[91] = 0;
		packetLengthsIn[92] = 0;
		packetLengthsIn[93] = 0;
		packetLengthsIn[94] = 0;
		packetLengthsIn[95] = 3;
		packetLengthsIn[96] = 0;
		packetLengthsIn[97] = 0;
		packetLengthsIn[98] = -1;
		packetLengthsIn[99] = 0;
		packetLengthsIn[100] = 0;
		packetLengthsIn[101] = 13;
		packetLengthsIn[102] = 0;
		packetLengthsIn[103] = -1;
		packetLengthsIn[104] = 0;
		packetLengthsIn[105] = 0;
		packetLengthsIn[106] = 0;
		packetLengthsIn[107] = 0;
		packetLengthsIn[108] = 0;
		packetLengthsIn[109] = 0;
		packetLengthsIn[110] = 0;
		packetLengthsIn[111] = 0;
		packetLengthsIn[112] = 0;
		packetLengthsIn[113] = 0;
		packetLengthsIn[114] = 0;
		packetLengthsIn[115] = 0;
		packetLengthsIn[116] = 0;
		packetLengthsIn[117] = 6;
		packetLengthsIn[118] = 0;
		packetLengthsIn[119] = 0;
		packetLengthsIn[120] = 1;
		packetLengthsIn[121] = 0;
		packetLengthsIn[122] = 6;
		packetLengthsIn[123] = 0;
		packetLengthsIn[124] = 0;
		packetLengthsIn[125] = 0;
		packetLengthsIn[126] = -1;
		packetLengthsIn[127] = 0;
		packetLengthsIn[128] = 2;
		packetLengthsIn[129] = 6;
		packetLengthsIn[130] = 0;
		packetLengthsIn[131] = 4;
		packetLengthsIn[132] = 6;
		packetLengthsIn[133] = 8;
		packetLengthsIn[134] = 0;
		packetLengthsIn[135] = 6;
		packetLengthsIn[136] = 0;
		packetLengthsIn[137] = 0;
		packetLengthsIn[138] = 0;
		packetLengthsIn[139] = 2;
		packetLengthsIn[140] = 0;
		packetLengthsIn[141] = 0;
		packetLengthsIn[142] = 0;
		packetLengthsIn[143] = 0;
		packetLengthsIn[144] = 0;
		packetLengthsIn[145] = 6;
		packetLengthsIn[146] = 0;
		packetLengthsIn[147] = 0;
		packetLengthsIn[148] = 0;
		packetLengthsIn[149] = 0;
		packetLengthsIn[150] = 0;
		packetLengthsIn[151] = 0;
		packetLengthsIn[152] = 1;
		packetLengthsIn[153] = 2;
		packetLengthsIn[154] = 0;
		packetLengthsIn[155] = 2;
		packetLengthsIn[156] = 6;
		packetLengthsIn[157] = 0;
		packetLengthsIn[158] = 0;
		packetLengthsIn[159] = 0;
		packetLengthsIn[160] = 0;
		packetLengthsIn[161] = 0;
		packetLengthsIn[162] = 0;
		packetLengthsIn[163] = 0;
		packetLengthsIn[164] = -1;
		packetLengthsIn[165] = -1;
		packetLengthsIn[166] = 0;
		packetLengthsIn[167] = 0;
		packetLengthsIn[168] = 0;
		packetLengthsIn[169] = 0;
		packetLengthsIn[170] = 0;
		packetLengthsIn[171] = 0;
		packetLengthsIn[172] = 0;
		packetLengthsIn[173] = 0;
		packetLengthsIn[174] = 0;
		packetLengthsIn[175] = 0;
		packetLengthsIn[176] = 0;
		packetLengthsIn[177] = 0;
		packetLengthsIn[178] = 0;
		packetLengthsIn[179] = 0;
		packetLengthsIn[180] = 0;
		packetLengthsIn[181] = 8;
		packetLengthsIn[182] = 0;
		packetLengthsIn[183] = 3;
		packetLengthsIn[184] = 0;
		packetLengthsIn[185] = 2;
		packetLengthsIn[186] = 0;
		packetLengthsIn[187] = 0;
		packetLengthsIn[188] = 8;
		packetLengthsIn[189] = 1;
		packetLengthsIn[190] = 0;
		packetLengthsIn[191] = 0;
		packetLengthsIn[192] = 12;
		packetLengthsIn[193] = 0;
		packetLengthsIn[194] = 0;
		packetLengthsIn[195] = 0;
		packetLengthsIn[196] = 0;
		packetLengthsIn[197] = 0;
		packetLengthsIn[198] = 0;
		packetLengthsIn[199] = 0;
		packetLengthsIn[200] = 2;
		packetLengthsIn[201] = 0;
		packetLengthsIn[202] = 0;
		packetLengthsIn[203] = 0;
		packetLengthsIn[204] = 0;
		packetLengthsIn[205] = 0;
		packetLengthsIn[206] = 0;
		packetLengthsIn[207] = 0;
		packetLengthsIn[208] = 4;
		packetLengthsIn[209] = 0;
		packetLengthsIn[210] = 4;
		packetLengthsIn[211] = 0;
		packetLengthsIn[212] = 0;
		packetLengthsIn[213] = 0;
		packetLengthsIn[214] = 7;
		packetLengthsIn[215] = 8;
		packetLengthsIn[216] = 0;
		packetLengthsIn[217] = 0;
		packetLengthsIn[218] = 10;
		packetLengthsIn[219] = 0;
		packetLengthsIn[220] = 0;
		packetLengthsIn[221] = 0;
		packetLengthsIn[222] = 0;
		packetLengthsIn[223] = 0;
		packetLengthsIn[224] = 0;
		packetLengthsIn[225] = 0;
		packetLengthsIn[226] = -1;
		packetLengthsIn[227] = 0;
		packetLengthsIn[228] = 6;
		packetLengthsIn[229] = 0;
		packetLengthsIn[230] = 1;
		packetLengthsIn[231] = 0;
		packetLengthsIn[232] = 0;
		packetLengthsIn[233] = 0;
		packetLengthsIn[234] = 6;
		packetLengthsIn[235] = 0;
		packetLengthsIn[236] = 6;
		packetLengthsIn[237] = 8;
		packetLengthsIn[238] = 1;
		packetLengthsIn[239] = 0;
		packetLengthsIn[240] = 0;
		packetLengthsIn[241] = 4;
		packetLengthsIn[242] = 0;
		packetLengthsIn[243] = 0;
		packetLengthsIn[244] = 0;
		packetLengthsIn[245] = 0;
		packetLengthsIn[246] = -1;
		packetLengthsIn[247] = 0;
		packetLengthsIn[248] = -1;
		packetLengthsIn[249] = 4;
		packetLengthsIn[250] = 0;
		packetLengthsIn[251] = 0;
		packetLengthsIn[252] = 6;
		packetLengthsIn[253] = 6;
		packetLengthsIn[254] = 0;
		packetLengthsIn[255] = 0;
		
		encoder = new RS2ProtocolEncoder(packetLengthsIn);
		decoder = new RS2ProtocolDecoder(packetLengthsIn);
	}
}
